package com.qf.quduba.controller;

import com.github.pagehelper.PageHelper;
import com.qf.quduba.VO.ResultVO;
import com.qf.quduba.entity.Type;
import com.qf.quduba.service.TypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作者：程意
 * 时间：2020/10/13 12:02
 */
@RestController
@CrossOrigin
@RequestMapping("/type")
public class TypeController {
    @Resource
    private TypeService typeService;

    @GetMapping("hits")
    public ResultVO findTypeHits(String typeId){
        int typeId1 = Integer.parseInt(typeId);
        Type typeInfo = typeService.findTypeHits(typeId1);
        if(typeInfo != null){
            return new ResultVO(1000,"成功",typeInfo);
        }else{
            return new ResultVO(1001,"失败",null);
        }
    }

    @GetMapping("typeInfo")
    public ResultVO findTypeInfo(@RequestParam(value = "page",defaultValue = "1",required = false)Integer page,String typeId){
        PageHelper.startPage(page,10);  //使用pageHelper插件实现分页效果
        int typeId1 = Integer.parseInt(typeId);
        Type typeInfo = typeService.findTypeInfo(typeId1);
        if(typeInfo != null){
            return new ResultVO(1000,"成功",typeInfo);
        }else{
            return new ResultVO(1001,"失败",null);
        }
    }

    @GetMapping("collect")
    public ResultVO findTypeCollect(String typeId){
        int typeId1 = Integer.parseInt(typeId);
        Type typeInfo = typeService.findTypeCollect(typeId1);
        if(typeInfo != null){
            return new ResultVO(1000,"成功",typeInfo);
        }else{
            return new ResultVO(1001,"失败",null);
        }
    }

    @GetMapping("getAllType")
    public ResultVO getAllType(){

        List<Type> allType = typeService.getAllType();
        if(allType != null){
            return new ResultVO(1000,"成功",allType);
        }else{
            return new ResultVO(1001,"失败",null);
        }
    }
}
